/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2025-03-05     Lenovo       the first version
 */
#ifndef __ADC_UART_H__

#define __ADC_UART_H__
#include <rtthread.h>
#include <rtdevice.h>
#include <board.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <send_all_control.h>
#include <string.h>
#include <aht10.h>
#include <as608.h>
#include <onenet.h>

// #define DBG_TAG "adc_uart"
// #define DBG_LVL         ADC_UART_DBG_LOG
#include <rtdbg.h>
/* 配置 LED 灯引脚 */
#define PIN_LED_B              GET_PIN(F, 11)      // PF11 :  LED_B        --> LED
#define PIN_LED_R              GET_PIN(F, 12)      // PF12 :  LED_R        --> LED
#define REFER_VOLTAGE       5.0         /* 参考电压 5V,数据精度乘以100保留2位小数*/
#define CONVERT_BITS        (1 << 12)   /* 转换位数为12位 */
#define Q7_RL               1000.00     /* 单位：欧姆 */
#define Q7_R0               6.64
#define CAL_PPM             10.00
#define Q2_RL               1000.00       /* 单位：欧姆 */
#define LOAD_RESISTANCE     4700       /* 负载电阻，单位：Ω */
/* UART配置 */
#define UART_DEV_NAME "uart3"
#define CMD_TIMEOUT_TICKS   RT_TICK_PER_SECOND  // 1秒超时
extern rt_adc_device_t adc_dev;

struct sensor_data {
    double co_ppm;      // 一氧化碳
    double smoke_ppm;   // 烟雾
    double keran_baifenbi;     // 可燃气体百分比
    float temperature;  // 温度
    float humidity;     // 湿度
};

int adc_init(void);
void read_sensors(struct sensor_data *data);
void control_thread_entry(void *parameter);
void senddata_thread_entry(void *parameter);
void send_data_to_touchscreen(const struct sensor_data *data);
void process_command(const char* cmd);
rt_err_t uart_rx_ind(rt_device_t dev, rt_size_t size);
int device_control_init(void);
void uart3_rx_callback(void);
void onenet_thread_entry(void *parameter);

#endif /* __ADC_UART_H__ */
